package com.itheima;

import com.itheima.testcase.domain.BookCase;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
//properties属性可以为当前测试用例添加临时的属性配置
//@SpringBootTest(properties = {"test.prop=testValue1"})
//args属性可以为当前测试用例添加临时的命令行参数
//@SpringBootTest(args={"--test.prop=testValue2"})
@SpringBootTest(properties = {"test.prop=testValue1"},args={"--test.prop=testValue2"})
public class PropertiesAndArgsTest {

    @Value("${test.prop}")
    private String msg;

    @Autowired
    private BookCase bookCase;

    @Test
    void testProperties(){
        System.out.println(msg);
        System.out.println(bookCase);
    }


    /**
     * 要使用template首先要获取template的对象，这个在我们导入jdbc的起步依赖，SpringBoot就加载了template的bean
     * 然后要有数据源对象，template里面的自带数据源就是Hikari
     */
    @Test
    void testJdbcTemplate(@Autowired JdbcTemplate jdbcTemplate) {

        String sql="select * from tbl_book ";
//        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
//        //得到的是map的list集合
//        System.out.println(maps);

        RowMapper<Book> rm=new RowMapper<Book>() {
            @Override
            public Book mapRow(ResultSet resultSet, int i) throws SQLException {
                int id = resultSet.getInt("id");
                String type = resultSet.getString("type");
                String name = resultSet.getString("name");
                String description = resultSet.getString("description");
                Book book=new Book();
                book.setId(id);
                book.setType(type);
                book.setName(name);
                book.setDescription(description);
                return book;
            }
        };
        List<Book> list = jdbcTemplate.query(sql, rm);
        System.out.println(list);

    }
}
